#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include "ui_mainwindow.h"
#include "searchboximpl.h"

#include "datamodel.h"
#include "stylemodel.h"
#include "configurationmodel.h"

#include <QSystemTrayIcon>
//

class QComboBox;
class QFontComboBox;

class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
    Q_OBJECT
public:		
    MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
    
    QString AppName();
    QString AppDisplayName();
    QString AppVersion();
    QString AppEditor();
    
protected:
    void closeEvent(QCloseEvent *event);    
    
private slots:
	void on_action_Search_triggered();
	void on_action_Options_triggered();
	void on_action_Apply_current_style_triggered();
	void on_actionStyle_editor_triggered();
	void on_actionPostScript_triggered();
	void on_actionExport_PDF_triggered();
	void on_actionPrint_triggered();
	void on_action_About_triggered();
	void on_actionAbout_Qt_triggered();
    void on_textEdit_cursorPositionChanged();
    void on_action_Color_triggered();
    void onClipboardDataChanged();
    void onTextFamily(const QString &f);
    void onTextSize(const QString &p);
    void onTextAlign(QAction *a);
    void on_textEdit_currentCharFormatChanged(QTextCharFormat format);
    void on_actionBold_triggered();
    void on_actionItalic_triggered();
    void on_actionUnderline_triggered();
    void on_action_New_triggered();
    void on_action_Save_triggered();
    void on_actionSave_as_triggered();
    void on_action_Open_triggered();
    void on_action_Quit_triggered();
    
    void onActionMenuRename();
    void onActionMenuDelete();
    void onActionMenuAddCategory();
    void onActionMenuAddPage(); 
    
    void onActionMenuMoveLeft();       
    void onActionMenuMoveRight();
    void onActionMenuMoveUp();
    void onActionMenuMoveDown();
    
    void onActionAddRootCategory();
    void onActionAddRootPage();   
    
    void onActionSysClose();
    void onActionSysShow();
    void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
    
    void onTreeClick(QTreeWidgetItem *treeItem, int col);
    void onTreeContextMenuRequested(QPoint pos);
    void onCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);   

private:    

    SearchBoxImpl *searchBox;
    QDockWidget *searchDock;
    QDockWidget *treeDock;

    QTreeWidget *treeWidget;
    QToolBar *treeToolBar;
    
    Model *mainModel; 
    StyleManager *m_styleManager; 
    ConfigurationManager *m_confManager; 
    
    QSystemTrayIcon *m_trayIcon;    
    bool m_closeFromMenu;

    QFontComboBox *comboFont;
    QComboBox *comboSize;        
    QToolBar *fontToolBar;
    QAction *actionAlignLeft;
    QAction *actionAlignRight;
    QAction *actionAlignCenter;
    QAction *actionAlignJustify;
    
    QToolBar *styleToolBar;
    QComboBox *comboStyle;
    
    QAction *actionAddRootCategory;
    QAction *actionAddRootPage;
    
    QAction *actionMenuAddCategory;
    QAction *actionMenuAddPage;
    QAction *actionMenuRename;
    QAction *actionMenuDelete;
    QAction *actionMenuMoveLeft;
    QAction *actionMenuMoveRight;
    QAction *actionMenuMoveUp;
    QAction *actionMenuMoveDown;
    QMenu *contextMenu;
    
    QAction *actionSysShow;
    QAction *actionSysClose;
    QMenu *sysTrayMenu;

    void createTreeDock();
    void createSearchDock();
    void createFontWidgets();
    void createContextMenu();
    void createSysTray();
    void FinalizeUI();        
    
    void openFile(QString fileName);

    void readSettings();
    void writeSettings(); 
    
    void doClose();
    void doCloseToTray();
    
    void setEditorColor(QColor color);
    void setTreeColor(QColor color);
    
    void applyConfiguration();

    void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
    void onFontChanged(const QFont &f);
    void onColorChanged(const QColor &c);
    void onAlignmentChanged(Qt::Alignment a);
    
};
#endif





